<template>
  <div>
      <table border="1" style="margin:0 auto">
          <tr v-for=' i in ding'>
              <td>{{i.number}}</td>
              <td>{{i.time}}</td>
              <td>价格：{{i.price}}</td>
            
              <td>
                  <!-- 展示收货人 -->
                  <span v-for="u in users" v-if='u.id==i.uid'>
                    {{u.username}}
                  </span>
              </td>
              <td>
                <span v-for="info in ding_infos" v-if="info.did == i.id">
                    <span v-for="good in info.goods">
                        <span v-for="g in goods" v-if='good.good == g.id'>
                            {{g.name}}
                            <img :src ='"http://qaqfc238e.bkt.clouddn.com/"+g.img' width="100" height="100">
                        </span>
                        <span>
                            数量：
                            {{good.num}}
                        </span>
                    </span>
                </span>

              </td>
              <td v-if="i.is_comment==0">
                  <button @click="add_comment(i.gid,i.id)">评价</button>
              </td>
              <td v-else>
                <button >已经评价</button>
              </td>
              
              <td>
                  <button @click="show_comment(i.gid)">查看所有</button>
              </td>
          </tr>
      </table>

  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            ding:[],
            goods:[],
            users:[],
            uid: sessionStorage.getItem('uid'),
            ding_infos:[],
            can_comment :0,
            str:'',
            content : '',
            gid:'',
        }
    },
    created(){
        this.get_ding()
    },
    methods:{
        show_comment(gid){
                this.$router.push({path:'/show_goods',query:{gid:gid}})
        },
        send_comment(){
            var formdata= new FormData
            formdata.append('uid',sessionStorage.getItem('uid'))
            formdata.append('gid',this.gid)
            formdata.append('content',this.content)

            axios.post('http://127.0.0.1:8000/myapp/inser_comment/',formdata).then(res=>{
                console.log(res.data)
            })
        },
        add_comment(gid,did){
            console.log(gid)
            if(sessionStorage.getItem('uid')){
                this.gid=gid
                this.$router.push({path:'/add_comment',query:{gid:gid,did:did}})
            }else{
                window.location.href= '/login'
            }
        },
        get_ding(){

            axios.get('http://127.0.0.1:8000/myapp/show_ding/',{
                params:{uid:sessionStorage.getItem('uid')}
            }).then(res=>{
                console.log(res.data)
                this.ding = res.data.data
                this.goods = res.data.goods
                this.users= res.data.users
                var infos = []
                for(let i=0;i<res.data.ding_infos.length;i++){
                    infos.push({
                        id: res.data.ding_infos[i].id,
                        did: res.data.ding_infos[i].did,
                        goods: JSON.parse(res.data.ding_infos[i].goods),
                    })
                }
                this.ding_infos = infos
                console.log(this.ding_infos)
            })
        }
    }
}
</script>

<style>

</style>